<!-- 商品库存查询 -->
<template>
  <el-dialog title="商品查询" :visible.sync="visible" fullscreen center append-to-body>
    <el-button class="miui-dialog-close-btn" @click="visible = false">关闭页面</el-button>
    <el-divider content-position="left">查询条件</el-divider>
    <el-form :inline="true" :model="dataForm">
      <el-form-item label="商品代码(条码)">
        <el-input v-model="code"></el-input>
      </el-form-item>
      <el-form-item label="商品名称">
        <el-input v-model="dataForm.name"></el-input>
      </el-form-item>
      <el-form-item label="定做类型" v-if="dataForm.ctgId == 3 || dataForm.ctgId == 4">
        <el-select v-model="dataForm.customizeType" @change="typeChangeHandle">
          <el-option v-for="item in bizData.customizeTypeData" :value="item.value" :label="item.label" :key="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="镜片材质" v-if="dataForm.ctgId == 3">
        <el-select v-model="dataForm.lensMaterial" clearable>
          <el-option v-for="item in bizData.opticMaterialData" :value="item.value" :label="item.label" :key="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="镜片种类" v-if="dataForm.ctgId == 3">
        <el-select v-model="dataForm.photometricClassification" clearable>
          <el-option v-for="item in bizData.photometricClassification" :value="item.value" :label="item.label" :key="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="折射率" v-if="dataForm.ctgId == 3">
        <el-select v-model="dataForm.refractiveIndex" clearable>
          <el-option v-for="item in bizData.refractivityData" :value="item.value" :label="item.label" :key="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="配件类型" v-if="dataForm.ctgId == 2">
        <el-select v-model="dataForm.accessoriesType">
          <el-option v-for="item in accessoryTypeData" :value="item.value" :label="item.label" :key="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="销售价格">
        <el-row>
          <el-col :span="11">
            <el-form-item label-width="0">
              <el-input v-model="dataForm.goodsPriceMin"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="2" style="text-align: center;">至</el-col>
          <el-col :span="11">
            <el-form-item label-width="0">
              <el-input v-model="dataForm.goodsPriceMax"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form-item>
      <el-form-item v-if="(dataForm.ctgId == 3 || dataForm.ctgId == 4) && dataForm.customizeType == '0'">
        <el-checkbox v-model="checked" :true-label="1" :false-label="0" @change="valueChangeHandle">是否展示0库存</el-checkbox>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" plain @click="getDataList">查询</el-button>
        <el-button type="info" plain @click="clearSearchForm">清空</el-button>
      </el-form-item>
      <el-row style="margin-top: 15px;" v-if="dataForm.ctgId == 3 || dataForm.ctgId == 4">
        <el-form-item>
          <el-radio-group v-model="eyesType" @change="getDataList">
            <el-radio :disabled="isHaveR" :label="1">右眼镜片</el-radio>
            <el-radio :disabled="isHaveL" :label="2">左眼镜片</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-row>
    </el-form>
    <el-divider content-position="left">查询数据</el-divider>
<!--    <el-row style="margin-bottom: 5px;">
      <el-button type="primary" plain @click="selectAndClose">选择并关闭</el-button>
    </el-row> -->
    <div class="avue-crud__pagination" style="margin-bottom: 25px;">
      <el-button icon="el-icon-check" type="primary" @click="selectAndClose" size="mini">选择并关闭</el-button>
      <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100, 200]" :page-size="pageSize" :total="totalPage" background layout="total, sizes, prev, pager, next">
      </el-pagination>
    </div>
    <div class="avue-crud">
      <el-table :data="dataList" height="calc(100vh - 215px)" ref="goodsTable" border v-loading="dataListLoading" @select="onTableSelect" @selection-change="handleSelectionChange">
        <el-table-column key="1" type="selection" header-align="center" align="center" width="45" :selectable="checkSelectable"></el-table-column>
        <el-table-column key="2" prop="code" header-align="center" align="center" label="商品代码"></el-table-column>
        <el-table-column key="3" prop="barcode" header-align="center" align="center" label="商品条码"></el-table-column>
        <el-table-column key="4" prop="name" header-align="center" align="center" label="商品名称"></el-table-column>
        <el-table-column key="5" prop="goodsPrice" header-align="center" align="center" label="零售价格"></el-table-column>
        <el-table-column key="34" prop="promotionPrice" header-align="center" align="center" label="促销价格"></el-table-column>
        <el-table-column key="6" prop="spec" header-align="center" align="center" label="型号" v-if="['1','2','5'].includes(dataForm.ctgId)"></el-table-column>

        <el-table-column key="7" prop="color" header-align="center" align="center" label="色号" v-if="dataForm.ctgId == '1'"></el-table-column>
        <el-table-column key="8" prop="frameMaterial" header-align="center" align="center" label="镜架材质" v-if="dataForm.ctgId == '1'">
          <template slot-scope="scope">
            {{getValNameByType(frameMaterialData,scope.row.frameMaterial)}}
          </template>
        </el-table-column>
        <el-table-column key="9" prop="goodsSize" header-align="center" align="center" label="镜架尺寸" v-if="dataForm.ctgId == '1'"></el-table-column>

        <el-table-column key="10" prop="accessoriesType" header-align="center" align="center" label="配件型"  v-if="dataForm.ctgId == '2'">
          <template slot-scope="scope">
            {{getValNameByType(accessoryTypeData,scope.row.accessoriesType)}}
          </template>
        </el-table-column>

        <el-table-column key="11" prop="mirrorBall" header-align="center" align="center" label="球镜" v-if="['3','4'].includes(dataForm.ctgId) && customizeType == '0'"></el-table-column>
        <el-table-column key="12" prop="columnMirror" header-align="center" align="center" label="柱镜" v-if="['3','4'].includes(dataForm.ctgId) && customizeType == '0'"></el-table-column>
        <el-table-column key="13" prop="toTheLight" header-align="center" align="center" label="下加光" v-if="dataForm.ctgId == '3' && customizeType == '0'"></el-table-column>
        <el-table-column key="14" header-align="center" align="center" label="球镜区间" v-if="['3','4'].includes(dataForm.ctgId) && customizeType == '1'">
          <template slot-scope="scope">
            <span>{{scope.row.customizedMirrorBallMin}}/{{scope.row.customizedMirrorBallMax}}</span>
          </template>
        </el-table-column>
        <el-table-column key="15" header-align="center" align="center" label="柱镜区间" v-if="['3','4'].includes(dataForm.ctgId) && customizeType == '1'">
          <template slot-scope="scope">
            <span>{{scope.row.customizedColumnMirrorMin}}/{{scope.row.customizedColumnMirrorMax}}</span>
          </template>
        </el-table-column>
        <el-table-column key="16" prop="axialDirection" header-align="center" align="center" label="轴位" v-if="dataForm.ctgId == '3' && customizeType == '1'"></el-table-column>
        <el-table-column key="17" header-align="center" align="center" label="下加光区间" v-if="dataForm.ctgId == '3' && customizeType == '1'">
          <template slot-scope="scope">
            {{scope.row.toTheLightMin}}/{{scope.row.toTheLightMax}}
          </template>
        </el-table-column>
        <el-table-column key="18" prop="refractiveIndex" header-align="center" align="center" label="折射率" v-if="dataForm.ctgId == '3'"></el-table-column>
        <el-table-column key="19" prop="photometricClassification" header-align="center" align="center" label="镜片分类" v-if="dataForm.ctgId == '3'">
          <template slot-scope="scope">
            {{getValNameByType(bizData.photometricClassification,scope.row.photometricClassification)}}
          </template>
        </el-table-column>
        <el-table-column key="20" prop="lensMaterial" header-align="center" align="center" label="材料分类" v-if="dataForm.ctgId == '3'">
          <template slot-scope="scope">
            {{getValNameByType(bizData.lensMaterial,scope.row.lensMaterial)}}
          </template>
        </el-table-column>

        <el-table-column key="21" prop="curvature" header-align="center" align="center" label="曲率" v-if="dataForm.ctgId == '4' &&  customizeType == '0'"></el-table-column>
        <el-table-column key="22" prop="diameter" header-align="center" align="center" label="直径" v-if="dataForm.ctgId == '4' &&  customizeType == '0'"></el-table-column>
        <el-table-column key="23" prop="axialDirection" header-align="center" align="center" label="轴位区间" v-if="dataForm.ctgId == '4' &&  customizeType == '1'">
          <template slot-scope="scope">
            {{scope.row.axialDirectionMin}} / {{scope.row.axialDirectionMax}}
          </template>
        </el-table-column>
        <el-table-column key="24" prop="curvature" header-align="center" align="center" label="曲率区间" v-if="dataForm.ctgId == '4' &&  customizeType == '1'">
          <template slot-scope="scope">
            {{scope.row.curvatureMin}} / {{scope.row.curvatureMax}}
          </template>
        </el-table-column>

        <el-table-column key="25" prop="useType" header-align="center" align="center" label="使用类型" v-if="dataForm.ctgId == '4'">
          <template slot-scope="scope">
            {{getValNameByType(bizData.useType,scope.row.useType)}}
          </template>
        </el-table-column>
        <el-table-column key="26" prop="disusedClassification" header-align="center" align="center" label="抛弃类型" v-if="dataForm.ctgId == '4'">
          <template slot-scope="scope">
            {{getValNameByType(bizData.disusedClassification,scope.row.disusedClassification)}}
          </template>
        </el-table-column>

        <el-table-column key="27" prop="primaryCapacity" header-align="center" align="center" label="主容量"  v-if="dataForm.ctgId == '5'"></el-table-column>
        <el-table-column key="28" prop="secondaryCapacity" header-align="center" align="center" label="次容量" v-if="dataForm.ctgId == '5'"></el-table-column>

        <el-table-column key="29" prop="mirrorBall" header-align="center" align="center" label="老花镜度数" v-if="dataForm.ctgId == '8'"></el-table-column>
        <el-table-column key="30" prop="batch" header-align="center" align="center" label="批次" v-if="dataForm.ctgId == '4' || dataForm.ctgId == '5'"></el-table-column>
        <el-table-column key="31" prop="invalidStr" header-align="center" align="center" label="效期" v-if="dataForm.ctgId == '4' || dataForm.ctgId == '5'"></el-table-column>
        <el-table-column key="32" prop="stockName" header-align="center" align="center" label="仓位" v-if="dataForm.selfFlag != '1'"></el-table-column>
        <el-table-column key="33" prop="storageQuantity" header-align="center" align="center" label="数量" v-if="((dataForm.selfFlag != '1') && (dataForm.customizeType != 1))"></el-table-column>
      </el-table>

    </div>

    <!-- <div class="avue-crud__pagination">
      <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" background layout="total, sizes, prev, pager, next, jumper"></el-pagination>
    </div> -->
  </el-dialog>
</template>

<script>
  import { filterParams,deduplicationBykey, deduplicationBykey1 } from "@/util/tools";
  import { remote } from '@/api/admin/dict'

  import { inventoryDetailFetchList, getGlassStorageSaleByPage } from "@/api/eims/storage";
  import { goodsFetchList } from '@/api/eims/goods'
  import { mapGetters } from "vuex";
  export default {
    data() {
      return {
        code: '',
        visible: false,
        checked: false,
        isHaveR: false,
        isHaveL: false,
        frameMaterialData: [],
        accessoryTypeData: [],
        customizeType: '',
        paramsData: {},
        eyesType: 1,
        reserveSelection: true,
        dataForm: {
          ctgId: "",
          showZero: '0',
          mirrorBall: "", // 球镜
          columnMirror: "", // 柱镜
          customizedMirrorBallMax: "",
          customizedMirrorBallMin: "",
          customizedColumnMirrorMax: "",
          customizedColumnMirrorMin: "",
          customizeType: "0",
          opticMaterial: "",
          opticType: "",
          key: "",
          person: "",
          address: ""
        },
        selected: true,
        rowItem: {},
        brandId: "",
        goodsId: "",
        dataList: [],
        pageIndex: 1,
        pageSize: 100,
        totalPage: 0,
        dataListLoading: false,
        selectList1: [],
        selectList2: [],
        selectListAll: [],
        flag: true
      };
    },
    computed: {
      ...mapGetters(["permissions", "bizData"])
    },
    methods: {
      init(data) {
        this.pageIndex = 1
        remote('frame_material').then(result => {
          this.frameMaterialData = result.data.data
        })
        remote('accessory_type').then(result => {
          this.accessoryTypeData = result.data.data
        })
        this.customizeType = ''
        this.paramsData = data.paramsData;
        this.tableData = data.tableData;
        this.code = ''
        for(let key in this.dataForm){
          if(key != 'ctgId'){
            this.dataForm[key] = ''
          }
        }
        this.checked = 0
        this.goodsId = ''
        this.dataForm.customizeType = "0";

        this.visible = true;
        this.selectListAll = data.tableData;
        this.selectList1 = []
        this.selectList2 = []
        this.dataList = []

        let isHaveR = this.selectListAll.some(item => {
          if(item.glassFlag == 'R'){
            return true
          }
        })
        let isHaveL = this.selectListAll.some(item => {
          if(item.glassFlag == 'L'){
            return true
          }
        })
        // console.log(isHave,isHave1)
        if(this.dataForm.ctgId == '3'){
          if(isHaveR){
            this.eyesType = 2
            this.isHaveR = true
          }else{
            this.eyesType = 1
            this.isHaveR = false
          }
          if(isHaveL){
            this.isHaveL = true
          }else{
            this.isHaveL = false
          }
          if(isHaveR && isHaveL){
            this.eyesType = ''
          }
        }else{
          this.isHaveR = false
          this.isHaveL = false
        }
        this.getDataList();

      },
      //  清空搜索表单
      clearSearchForm() {
        for (let key in this.dataForm) {
          if(key == 'ctgId' || key == 'customizeType'){
          }else{
            this.dataForm[key] = "";
          }
        }
      },
      // 获取数据列表
      getDataList() {
        this.dataForm.ctgId = this.paramsData.ctgId;
        this.dataForm.stockId = this.paramsData.stockId;
        this.dataForm.selfFlag = this.paramsData.selfFlag
        this.dataListLoading = true;
        if(this.code.indexOf('.') == -1){
          this.dataForm.barcode = this.code
        }else{
          this.dataForm.code = this.code
        }
        this.dataList = []
        //  判断是否是镜片类商品
        if (this.dataForm.ctgId == 3 || this.dataForm.ctgId == 4) {
          if(this.dataForm.ctgId == '3'){
            this.dataForm.brandId = (this.goodsId) ? this.brandId : ''
          }
          if(this.dataForm.selfFlag){
            //  自镜
            this.dataForm.mirrorBall = '0'
            this.dataForm.columnMirror = '0'
          }else{
            //  非自镜
            if (this.dataForm.customizeType == "0") {
              delete this.dataForm.customizedMirrorBallMax;
              delete this.dataForm.customizedColumnMirrorMax;
              delete this.dataForm.customizedMirrorBallMin;
              delete this.dataForm.customizedColumnMirrorMin;
              // 球镜赋值--成品片
              this.dataForm.mirrorBall = this.eyesType == "1" ? this.paramsData.ballGlassOd : this.paramsData.ballGlassOs;
              this.dataForm.columnMirror = this.eyesType == "1" ? this.paramsData.postGlassOd : this.paramsData.postGlassOs;
            } else {
              delete this.dataForm.mirrorBall;
              delete this.dataForm.columnMirror;
              // 订做球镜上限赋值--定做片
              this.dataForm.customizedMirrorBallMax = this.eyesType == "1" ? this.paramsData.ballGlassOd : this.paramsData
                .ballGlassOs;
              this.dataForm.customizedColumnMirrorMax = this.eyesType == "1" ? this.paramsData.postGlassOd : this.paramsData
                .postGlassOs;
              this.dataForm.customizedMirrorBallMin = this.eyesType == "1" ? this.paramsData.ballGlassOd : this.paramsData
                .ballGlassOs;
              this.dataForm.customizedColumnMirrorMin = this.eyesType == "1" ? this.paramsData.postGlassOd : this.paramsData
                .postGlassOs;
            }
          }
        } else {
          this.dataForm.customizeType = "";
          this.dataForm.brandId = "";
          this.dataForm.mirrorBall = ''
          this.dataForm.columnMirror = ''
          this.dataForm.customizedMirrorBallMax = ''
          this.dataForm.customizedColumnMirrorMax = ''
          this.dataForm.customizedMirrorBallMin = ''
          this.dataForm.customizedColumnMirrorMin = ''
        }

        let params1 = { current: this.pageIndex, size: this.pageSize };
        let params2 = filterParams(this.dataForm);
          if (this.dataForm.selfFlag) {   //  如果是自镜自架
            if (this.dataForm.ctgId == '3' || this.dataForm.ctgId == '4') {
              goodsFetchList(Object.assign(params1, params2)).then(
                response => {
                  this.dataList = response.data.data.records;
                  this.dataList.forEach(item => {
                    item.goodsId = item.id
                  })
                  this.totalPage = response.data.data.total;
                  this.customizeType = this.dataForm.customizeType
                  this.$nextTick(() => {
                    this.selectListAll.forEach(item => {
                      for (let i = 0; i < this.dataList.length; i++) {
                        if (this.dataList[i].goodsId == item.goodsId && item.ctgId == this.dataForm.ctgId && item.eyesType == this.eyesType) {
                          this.$refs.goodsTable.toggleRowSelection(this.dataList[i], true);
                        }
                      }
                    });
                  });
                }
              );
            } else {
              goodsFetchList(Object.assign(params1, params2)).then(
                response => {
                  this.dataList = response.data.data.records;
                  this.dataList.forEach(item => {
                    item.goodsId = item.id
                  })
                  this.totalPage = response.data.data.total;
                  this.customizeType = this.dataForm.customizeType
                  this.$nextTick(() => {
                    this.selectListAll.forEach(item => {
                      for (let i = 0; i < this.dataList.length; i++) {
                        if (this.dataList[i].goodsId == item.goodsId) {
                          this.$refs.goodsTable.toggleRowSelection(this.dataList[i], true);
                        }
                      }
                    });
                  });
                }
              );
            }
          } else {    //  非自镜自架
            console.log(this.selectList1)
            switch(this.dataForm.ctgId){
              case '3':
                if(this.eyesType){
                  getGlassStorageSaleByPage(Object.assign(params1, params2)).then(response => {
                    this.dataList = response.data.data.records;
                    this.dataList.forEach(item => {
                      item.goodsId = item.id
                    })
                    this.totalPage = response.data.data.total;
                    this.customizeType = this.dataForm.customizeType
                    this.$nextTick(() => {
                      this.selectListAll.forEach(item => {
                        for (let i = 0; i < this.dataList.length; i++) {
                          if (this.dataList[i].goodsId == item.goodsId && item.eyesType == this.eyesType) {
                            this.$refs.goodsTable.toggleRowSelection(this.dataList[i], true);
                          }
                        }
                      });
                    });
                  });
                }
                break;
              case '4':
                if(this.eyesType){
                  getGlassStorageSaleByPage(Object.assign(params1, params2)).then(response => {
                    this.dataList = response.data.data.records;
                    this.dataList.forEach(item => {
                      item.goodsId = item.id
                    })
                    this.totalPage = response.data.data.total;
                    this.customizeType = this.dataForm.customizeType
                    this.$nextTick(() => {
                      this.selectListAll.forEach(item => {
                        for (let i = 0; i < this.dataList.length; i++) {
                          if (this.dataList[i].goodsId == item.goodsId && item.eyesType == this.eyesType && this.dataList[i].batch == item.batch && this.dataList[i].invalidTime == item.invalidTime) {
                            this.$refs.goodsTable.toggleRowSelection(this.dataList[i], true);
                          }
                        }
                      });
                    });
                  });
                }
                break;
              case '5':
                  getGlassStorageSaleByPage(Object.assign(params1, params2)).then(response => {
                    this.dataList = response.data.data.records;
                    this.dataList.forEach(item => {
                      item.goodsId = item.id
                    })
                    this.totalPage = response.data.data.total;
                    this.customizeType = this.dataForm.customizeType
                    this.$nextTick(() => {
                      this.selectListAll.forEach(item => {
                        for (let i = 0; i < this.dataList.length; i++) {
                          if (this.dataList[i].goodsId == item.goodsId && this.dataList[i].batch == item.batch && this.dataList[i].invalidTime == item.invalidTime) {
                            this.$refs.goodsTable.toggleRowSelection(this.dataList[i], true);
                          }
                        }
                      });
                    });
                  });
                break;
              default:
                getGlassStorageSaleByPage(Object.assign(params1, params2)).then(response => {
                  this.dataList = response.data.data.records;
                  this.dataList.forEach(item => {
                    item.goodsId = item.id
                  })
                  this.totalPage = response.data.data.total;
                  this.customizeType = this.dataForm.customizeType
                  this.$nextTick(() => {
                    this.selectListAll.forEach(item => {
                      for (let i = 0; i < this.dataList.length; i++) {
                        if (this.dataList[i].goodsId == item.goodsId) {
                          this.$refs.goodsTable.toggleRowSelection(this.dataList[i], true);
                        }
                      }
                    });
                  });
                });
            }

          }
        this.dataListLoading = false;
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val;
        this.pageIndex = 1;
        this.getDataList();
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = val;
        this.getDataList();
      },
      cellClass(row) {
        if (row.columnIndex === 0) {
          return 'disabledCheck'
        }
      },
      // 定做类型改变
      typeChangeHandle(){
        let isHaveR = this.selectListAll.some(item => {
          if(item.glassFlag == 'R'){
            return true
          }
        })
        let isHaveL = this.selectListAll.some(item => {
          if(item.glassFlag == 'L'){
            return true
          }
        })
        // console.log(isHave,isHave1)
        if(isHaveR){
          this.isHaveR = true
        }else{
          this.isHaveR = false
        }
        if(isHaveL){
          this.isHaveL = true
        }else{
          this.isHaveL = false
        }
      },
      //  判断当前行是否可选
      checkSelectable(row) {
        if (this.goodsId && this.dataForm.ctgId == "3") {
          return row.id == this.goodsId;
        } else {
          return true;
        }
      },
      //  判断当前操作的属性是勾选还是取消勾选
      onTableSelect(rows,row) {
        this.selected = rows.length && rows.indexOf(row) !== -1
        this.rowItem = row
      },
      handleSelectionChange(val) {
        switch(this.dataForm.ctgId){
          case '3':
            if(val.length > 0){
              this.goodsId = true
              this.brandId = val[0].brandId;
              if(this.dataForm.selfFlag) val[0].goodsPrice = 0
              val[0].customizeType = this.dataForm.customizeType;
              val[0].goodsQuantity = 1;
              val[0].discountRate = "1";
              val[0].discountPrice = "0";
              val[0].removePrice = "0";
              if (this.eyesType == "1") {
                val[0].eyesType = "1";
                val[0].glassFlag = "R";
                val[0].goodsDescription = "右眼镜片";
              } else {
                val[0].eyesType = "2";
                val[0].glassFlag = "L";
                val[0].goodsDescription = "左眼镜片";
              }
            }else{
              this.brandId = "";
              this.goodsId = "";
            }
            this["selectList" + this.eyesType] = val;
            if(this.selected){
              this.selectListAll = this.uniqObjInArray(this.selectListAll.concat(this.selectList1,this.selectList2))
              this.selectListAll.forEach((item,index) => {
                if(item.ctgId == 3 && !item.glassFlag){
                  this.selectListAll.splice(index,1)
                }
              })
            }else{
              this.selectListAll.forEach((item,index) => {
                if(item.goodsId == this.rowItem.goodsId && item.glassFlag == this.rowItem.glassFlag){
                  this.selectListAll.splice(index,1)
                }
              })
            }
            break;
          case '4':
            if(val.length > 0){
              this.goodsId = true
              this.brandId = val[0].brandId;
              val.forEach(item => {
                item.customizeType = this.dataForm.customizeType;
                item.goodsQuantity = 1;
                item.discountRate = '1';
                item.discountPrice = '0';
                item.removePrice = '0';
                if(this.eyesType == '1'){
                  item.eyesType = '1';
                  item.glassFlag = 'R';
                  item.goodsDescription = '隐形右眼镜片';
                }else{
                  item.eyesType = '2';
                  item.glassFlag = 'L';
                  item.goodsDescription = '隐形左眼镜片';
                }
              })
            }else{
              this.brandId = "";
              this.goodsId = "";
            }
            this["selectList" + this.eyesType] = val;
            if(this.selected){
              this.selectListAll = deduplicationBykey1(this.selectListAll.concat(this.selectList1,this.selectList2),'goodsId','batch','invalidTime','glassFlag','goodsDescription')
              // this.selectListAll = this.uniqObjInArray(this.selectListAll.concat(this.selectList1,this.selectList2))
              this.selectListAll.forEach((item,index) => {
                if(item.ctgId == 4 && !item.glassFlag){
                  this.selectListAll.splice(index,1)
                }
              })
            }else{
              this.selectListAll.forEach((item,index) => {
                if(item.goodsId == this.rowItem.goodsId && item.glassFlag == this.rowItem.glassFlag && item.batch == this.rowItem.batch && item.invalidTime == this.rowItem.invalidTime){
                  this.selectListAll.splice(index,1)
                }
              })
            }
            break;
          case '5':
            if(this.selected) {
              val.forEach(item => {
                  item.goodsQuantity = 1;
                  item.discountRate = "1";
                  item.discountPrice = "0";
                  item.removePrice = "0";
                  item.goodsDescription = "护理液";
                })
                this.selectListAll = deduplicationBykey(this.selectListAll.concat(val),'goodsId','batch','invalidTime')
                // this.selectListAll = this.uniqObjInArray(this.selectListAll.concat(val))
            }else{
              this.selectListAll.forEach((item,index) => {
                if(item.goodsId == this.rowItem.goodsId && item.batch == this.rowItem.batch && item.invalidTime == this.rowItem.invalidTime){
                  this.selectListAll.splice(index,1)
                }
              })
            }
            break;
          default:
            if(this.selected) {
              val.forEach(item => {
                if(this.dataForm.selfFlag && item.ctgId == '1') item.goodsPrice = 0
                item.goodsQuantity = 1;
                item.discountRate = "1";
                item.discountPrice = "0";
                item.removePrice = "0";
                if(this.dataForm.ctgId == '1'){
                  item.goodsDescription = "镜架";
                  item.glassFlag = "F";
                }else if(this.dataForm.ctgId == '2'){
                  item.goodsDescription = "配件";
                }else if(this.dataForm.ctgId == '6'){
                  item.goodsDescription = "太阳镜";
                }else if(this.dataForm.ctgId == '7'){
                  item.goodsDescription = "耗材";
                }else if(this.dataForm.ctgId == '8'){
                  item.goodsDescription = "视光";
                }
              })
              this.selectListAll = this.uniqObjInArray(this.selectListAll.concat(val))
            }else{
              this.selectListAll.forEach((item,index) => {
                if(item.id == this.rowItem.id){
                  this.selectListAll.splice(index,1)
                }
              })
            }
        }
      },
      uniqObjInArray(objarray){
          let len = objarray.length;
          let tempJson = {};
          let res = [];
          for(let i = 0;i < len;i++){
              //取出每一个对象
              tempJson[JSON.stringify(objarray[i])] = true;
          }
          let keyItems= Object.keys(tempJson);
          for(let j = 0;j < keyItems.length;j++){
              res.push(JSON.parse(keyItems[j]));
          }
          return res;
      },
      //  选择并关闭
      selectAndClose() {
        let table = JSON.parse(JSON.stringify(this.tableData))
        let ctgId = this.dataForm.ctgId
        this.reserveSelection = false
        let selectIdArr = []
        let detailIdArr = []
        this.selectListAll.forEach(item => {
          if(item.ctgId == '3'){
            selectIdArr.push({goodsId: item.goodsId,glassFlag: item.glassFlag})
          }else if(item.ctgId == '4'){
            selectIdArr.push({goodsId: item.goodsId,glassFlag: item.glassFlag,batch: item.batch,invalidTime: item.invalidTime})
          }else if(item.ctgId == '5'){
            selectIdArr.push({goodsId: item.goodsId,batch: item.batch,invalidTime: item.invalidTime})
          }else{
            selectIdArr.push(item.goodsId)
          }
        })

        table.forEach(item => {
          if(item.ctgId == '3'){
            detailIdArr.push({goodsId: item.goodsId,glassFlag: item.glassFlag})
          }else if(item.ctgId == '4'){
            detailIdArr.push({goodsId: item.goodsId,glassFlag: item.glassFlag,batch: item.batch,invalidTime: item.invalidTime})
          }else if(item.ctgId == '5'){
            detailIdArr.push({goodsId: item.goodsId,batch: item.batch,invalidTime: item.invalidTime})
          }else{
            detailIdArr.push(item.goodsId)
          }
        })
        this.tableData.forEach((item, index) => {
          if(ctgId == '3'){
            if(item.ctgId == ctgId){
              let result = selectIdArr.some(term => {
                if(term.goodsId == item.goodsId && term.glassFlag == item.glassFlag){
                  return true
                }
              })
              if(!result){
                this.tableData.splice(index,1)
              }
              // if(result){
              //   for(let i = 0; i < selectIdArr.length; i++){
              //     if(item.goodsId == selectIdArr.goodsId && item.glassFlag == selectIdArr.glassFlag){
              //       this.tableData.splice(index,1)
              //     }
              //   }
              // }else{
              //   this.tableData.splice(index,1)
              // }
            }
          }else if(ctgId == '4'){
            if (item.ctgId == ctgId) {
              let result = selectIdArr.some(term => {
                if(term.goodsId == item.goodsId && term.glassFlag == item.glassFlag && term.batch == item.batch && term.invalidTime == item.invalidTime){
                  return true
                }
              })
              if(!result){
                this.tableData.splice(index,1)
              }
              // if(result){
              //   for(let i = 0; i < selectIdArr.length; i++){
              //     if(item.goodsId == selectIdArr[i].goodsId && item.glassFlag == selectIdArr[i].glassFlag && item.batch == selectIdArr[i].batch && item.invalidTime == selectIdArr[i].invalidTime){
              //       this.tableData.splice(index,1)
              //     }
              //   }
              // }else{
              //   this.tableData.splice(index,1)
              // }
            }
          }else if(ctgId == '5'){
            if(item.ctgId == ctgId) {
              let result = selectIdArr.some(term => {
                if(term.goodsId == item.goodsId && term.batch == item.batch && term.invalidTime == item.invalidTime){
                  return true
                }
              })
              if(!result){
                this.tableData.splice(index,1)
              }
              // if(result){
              //   for(let i = 0; i < selectIdArr.length; i++){
              //     if(item.goodsId == selectIdArr[i].goodsId && item.batch == selectIdArr[i].batch && item.invalidTime == selectIdArr[i].invalidTime){
              //       this.tableData.splice(index,1)
              //     }
              //   }
              // }else{
              //   this.tableData.splice(index,1)
              // }
            }
          }else{
            if (item.ctgId == ctgId) {
              if (selectIdArr.indexOf(item.goodsId) == -1) {
                this.tableData.splice(index, 1)
              }
            }
          }
        })
        //  将选中的商品中选购商品列表不存在的商品放进列表，并将存在的商品替换
        this.selectListAll.forEach(item => {
          if(item.ctgId == '3'){
            let result = detailIdArr.some(term => {
              if(term.goodsId == item.goodsId && term.glassFlag == item.glassFlag){
                return true
              }
            })
            if(result){
              for (let i = 0; i < this.tableData.length; i++) {
                if (this.tableData[i].goodsId == item.goodsId && this.tableData[i].glassFlag == item.glassFlag) {
                  this.tableData[i] = item
                }
              }
            }else{
              this.tableData.push(item)
            }
          }else if(item.ctgId == '4'){
            let result = detailIdArr.some(term => {
              if(term.goodsId == item.goodsId && term.glassFlag == item.glassFlag && term.batch == item.batch && term.invalidTime == item.invalidTime){
                return true
              }
            })
            if(result){
              for (let i = 0; i < this.tableData.length; i++) {
                if (this.tableData[i].goodsId == item.goodsId && this.tableData[i].glassFlag == item.glassFlag && this.tableData[i].batch == item.batch && this.tableData[i].invalidTime == item.invalidTime) {
                  this.tableData[i] = item
                }
              }
            }else{
              this.tableData.push(item)
            }
          }else if(item.ctgId == '5'){
            let result = detailIdArr.some(term => {
              if(term.goodsId == item.goodsId && term.batch == item.batch && term.invalidTime == item.invalidTime){
                return true
              }
            })
            if(result){
              for (let i = 0; i < this.tableData.length; i++) {
                if (this.tableData[i].goodsId == item.goodsId && this.tableData[i].batch == item.batch && this.tableData[i].invalidTime == item.invalidTime) {
                  this.tableData[i] = item
                }
              }
            }else{
              this.tableData.push(item)
            }
          }else{
            if (detailIdArr.indexOf(item.goodsId) == -1) {
              this.tableData.push(item)
            } else {
              for (let i = 0; i < this.tableData.length; i++) {
                if (this.tableData[i].goodsId == item.goodsId) {
                  this.tableData[i] = item
                }
              }
            }
          }
        })
        this.visible = false
        this.$emit("refreshForm", {
          value: this.tableData,
          ctgId: this.dataForm.ctgId
        });
      },
      getValNameByType(data,type) {
        let obj = {}
        obj = data.find(item => {
          return item.value == type
        })
        if(obj && obj.label){
          return obj.label
        }
      },
      //  多选框值转换
      valueChangeHandle(val){
        if(val == '1'){
          this.$set(this.dataForm,'showZero','1')
        }else{
          this.$set(this.dataForm,'showZero','0')
        }
        this.dataForm = {...this.dataForm}
      },
    }
  };
</script>

<style lang="scss" scoped>
  .el-table .disabledCheck .cell .el-checkbox__inner {
    display: none !important;
  }
</style>
